package com.bvgol.examples.nio.zerocp.nio;/**
 * @Classname Server
 * @Description TODO
 * @Date 2021/7/6 9:54
 * @Created by GUOCHEN
 */

import lombok.SneakyThrows;

import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.nio.ByteBuffer;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;

/**
 * @program: my-spring-completely
 * @description:
 * @author: GUOCHEN
 * @create: 2021/07/06 09:54
 */
public class Server {
    @SneakyThrows
    public static void main(String[] args) {
        InetSocketAddress address = new InetSocketAddress(7001);
        ServerSocketChannel open = ServerSocketChannel.open();
        ServerSocket socket = open.socket();
        socket.bind(address);

        ByteBuffer byteBuffer = ByteBuffer.allocate(4096);

        while (true){
            SocketChannel accept = open.accept();
            accept.configureBlocking(false);
            int read = 0;
            while (-1 == read) {
                read = accept.read(byteBuffer);
                byteBuffer.rewind();//重置
            }


        }

    }
}
